package com.jcfk.eam.controller.mt;

import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;
import com.jcfk.eam.controller.parent.EamGrantRecordController;
import com.jcfk.eam.controller.parent.EamGrantRecordDetailController;
import com.jcfk.eam.domain.dto.main.EamGrantRecordDTO;
import com.jcfk.eam.domain.dto.main.EamGrantRecordDetailDTO;
import com.jcfk.eam.domain.dto.main.EamRepayRecordDTO;
import com.jcfk.eam.domain.query.main.EamRepayRecordQuery;
import com.jcfk.eam.domain.query.main.EamGrantRecordQuery;
import com.jcfk.eam.enums.AssetKind;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 量检具发放记录 服务接口
 *
 * @author yql
 * @email 522891237@gqq.com
 * @date 2024-07-29
 */
@Api(tags = {"量检具发放记录管理"})
@RestController
@RequestMapping("mtgrantrecord")
public class MtGrantRecordController {
    @Autowired
    private EamGrantRecordController eamGrantRecordController;

    @Autowired
    private EamGrantRecordDetailController eamGrantRecordDetailController;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamGrantRecordQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询发放记录")
    @PostMapping("/queryByPage")
    public RetPage<EamGrantRecordDTO> queryByPage(@RequestBody ReqPageParam<EamGrantRecordQuery> requestParam) {
        requestParam.getData().setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        return eamGrantRecordController.queryByPage(requestParam);
    }

    /**
     * 获取发放记录列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamGrantRecordQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取发放记录列表", notes = "获取发放记录列表", httpMethod = "POST")
    @PostMapping("getDetails")
    public RetResult<List<EamGrantRecordDetailDTO>> getDetails(@RequestBody EamGrantRecordQuery query) {
        query.setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        return eamGrantRecordController.getDetails(query);
    }

    /**
     * 分页归还列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamGrantRecordDetailQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询归还记录明细")
    @PostMapping("/queryRepayByPage")
    public RetPage<EamRepayRecordDTO> queryRepayByPage(@RequestBody ReqPageParam<EamRepayRecordQuery> requestParam) {
        requestParam.getData().setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        return eamGrantRecordController.queryRepayByPage(requestParam);
    }

    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamGrantRecordQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取发放记录列表", notes = "获取发放记录列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<EamGrantRecordDTO>> getList(@RequestBody EamGrantRecordQuery query) {
        query.setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        return eamGrantRecordController.getList(query);
    }


    /**
     * 发放记录
     * 根据id 查询详情
     */
    @ApiOperation("查询发放记录")
    @GetMapping("/get/{id}")
    public RetResult<EamGrantRecordDTO> get(@PathVariable("id") String id) {
        return eamGrantRecordController.get(id);
    }

    /**
     * 归还记录
     * 根据id 查询详情
     */
    @ApiOperation("查询归还记录")
    @GetMapping("/getDetails/{id}")
    public RetResult<EamRepayRecordDTO> getDetails(@PathVariable("id") String id) {
        return eamGrantRecordController.getDetails(id);
    }


    /**
     * 添加/更新管理发放记录
     */
    @ApiOperation("保存发放记录")
    @PostMapping("/save")
    @RequestLogHeader(modular = "发放记录管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamGrantRecordDTO eamGrantRecord) {
        eamGrantRecord.setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        return eamGrantRecordController.save(eamGrantRecord);
    }

    /**
     * 添加/更新管理归还记录
     */
    @ApiOperation("保存归还记录")
    @PostMapping("/saveReturnRecords")
    @RequestLogHeader(modular = "归还记录管理", businessType = "保存")
    public RetResult<?> saveReturnRecords(@RequestBody @Valid EamGrantRecordDetailDTO eamGrantRecordDetail) {
        eamGrantRecordDetail.setIsRepay(1);
        return eamGrantRecordDetailController.save(eamGrantRecordDetail);
    }

    /**
     * 批量删除发放记录
     */
    @ApiOperation("批量删除发放记录")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "发放记录管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamGrantRecordDTO eamGrantRecord) {
        return eamGrantRecordController.delete(eamGrantRecord);
    }

    /**
     * 批量审核发放记录
     */
    @ApiOperation("批量审核发放记录")
    @PostMapping("/examine")
    @RequestLogHeader(modular = "发放记录管理", businessType = "批量审核")
    public RetResult<?> examine(@RequestBody EamGrantRecordDTO eamGrantRecord) {
        return eamGrantRecordController.examine(eamGrantRecord);
    }

    /**
     * 删除发放记录
     */
    @ApiOperation("删除发放记录")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "发放记录管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        return eamGrantRecordController.deleteItem(id);
    }
}
